<!DOCTYPE html>
<html lang="en">

<head>
    <base href="{#location.origin#}/res/smartadmin-402/" />
    <meta charset="utf-8">
    <title>
        登录 - Uim部署控制台 v1.0
    </title>
    <meta name="description" content="Login">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no, minimal-ui">
    <!-- Call App Mode on ios devices -->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!-- Remove Tap Highlight on Windows Phone IE -->
    <meta name="msapplication-tap-highlight" content="no">
    <!-- base css -->
    <link rel="stylesheet" media="screen, print" href="css/vendors.bundle.css">
    <link rel="stylesheet" media="screen, print" href="css/app.bundle.css">
    <!-- Place favicon.ico in the root directory -->
    <link rel="apple-touch-icon" sizes="180x180" href="img/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="img/favicon/favicon-32x32.png">
    <link rel="mask-icon" href="img/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <!-- Optional: page related CSS-->
    <link rel="stylesheet" media="screen, print" href="css/page-login.css">
</head>

<body>
    <div class="blankpage-form-field">
        <div
            class="page-logo m-0 w-100 align-items-center justify-content-center rounded border-bottom-left-radius-0 border-bottom-right-radius-0 px-4">
            <a href="javascript:void(0)" class="page-logo-link d-flex align-items-center">
                <img src="img/logo.png" alt="Uim部署控制台 v1.0" aria-roledescription="logo">
                <span class="page-logo-text mr-1">Uim部署控制台 v1.0</span>
            </a>
        </div>
        <div class="card p-4 border-top-left-radius-0 border-top-right-radius-0">
            <form>

                <div class="form-group">
                    <label class="form-label" for="username">登录名</label>
                    <input type="text" id="username" class="form-control" placeholder="用户名 / 邮箱 / 手机号" value="admin">
                    <span class="help-block">
                        请输入登录名
                    </span>
                </div>
                <div class="form-group">
                    <label class="form-label" for="password">密码</label>
                    <input type="password" id="password" class="form-control" placeholder="登录密码" value="123456">
                    <span class="help-block">
                        请输入密码
                    </span>
                </div>
                <div class="form-group text-left">
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" id="rememberme" checked>
                        <label class="custom-control-label" for="rememberme"> 一周内免登录</label>
                    </div>
                </div>
                <button type="button" class="btn btn-default float-right btn-login">安全登录</button>

            </form>
        </div>
        <div class="blankpage-footer text-center">
            <a href="javascript:void(0)"><strong>忘记密码</strong></a> | <a
                href="javascript:void(0)"><strong>社区求助</strong></a>
        </div>
    </div>
    <div class="login-footer p-2">
        <div class="row">
            <div class="col col-sm-12 text-center">
                <i><strong>系统消息：</strong> {#uim.config.system_message#}</i>
            </div>
        </div>
    </div>
    <video poster="img/backgrounds/clouds.png" id="bgvid" playsinline autoplay muted loop>
        <source src="media/video/cc.webm" type="video/webm">
        <source src="media/video/cc.mp4" type="video/mp4">
    </video>
    {#include template="include/color-profile"/#}
    <script src="js/vendors.bundle.js"></script>
    <script src="js/app.bundle.js"></script>
    <script src="js/notifications/toastr/toastr.js"></script>
    <!-- Page related scripts -->

    <script>

        // 隐藏输入框
        $('.form-control').on('input', function () {
            $(this).next().hide();
        })
        $('.form-control').on('keydown', function (e) {
            var currKey = 0, e = e || event;
            currKey = e.keyCode || e.which || e.charCode;
            if (13 == currKey) {
                $('.btn-login').click()
            }
        })
        $('.btn-login').click(function () {
            if ($(this).attr('disabled')) return;

            var username = $('#username').val();
            var password = $('#password').val();
            if (!username) return $('#username').focus().next().show();
            if (!password) return $('#password').focus().next().show();

            $(this).attr('disabled', true);

            uim.api.emit({
                code: 'user.account.login/1.0',
                data: {
                    user_name: username,
                    login_password: uim.MD5('login_password_' + password),
                    expiry_time: $('#rememberme').prop('checked') ? (86400 * 7) : 10,
                },
                success: function (data) {
                    data.head_portrait = data.head_portrait || '/default-avatar-m.png';
                    Object.assign(uim.session, data);
                    uim.save('session');
                    uim.view('main');
                    // if ($('#rememberme').prop('checked')) {
                    //     uim.session.expiry_time = uim.dateTime('+10000')
                    // } else {
                    //     uim.session.expiry_time = uim.dateTime()
                    // }

                    // 登录验证成功后，继续获取权限列表
                    // get_power_list();

                },
                error: function (ret) {
                    toastr.error(ret.text)
                    initApp.playSound('media/sound', 'messagebox')

                    bootbox.alert({
                        title: "<i class='fal fa-times-circle text-danger mr-2'></i> " + ret.text,
                        message: "<span><strong>code:</strong> " + ret.text + "</span>",
                        centerVertical: true,
                        swapButtonOrder: true,
                        buttons: {
                            ok: {
                                label: '确定',
                                className: 'btn-danger shadow-0'
                            },
                        },
                        className: "modal-alert",
                        closeButton: false,
                        callback: function () {
                            $('.btn-login').attr('disabled', false);
                        }
                    });
                    return true;
                }
            })
        });
        var get_power_list = function () {

            uim.api.emit({
                code: 'user.account.power/1.0',
                data: {
                    role_ids: ''
                },
                success: function (data) {
                    var power = { _childs: [] };
                    var tmp_power_node = {};
                    $(data.power_list).each(function () {
                        if (this.ext_data) this.ext_data = JSON.parse(this.ext_data);
                        // 先放到临时对象中
                        if (!tmp_power_node['_' + this.power_id]) {
                            tmp_power_node['_' + this.power_id] = { _childs: [] }
                        }
                        tmp_power_node['_' + this.power_id]._data = this;
                        if (!this.parent_id) {
                            // 如果是顶级节点，则加入到power对象
                            power[this.power_code] = tmp_power_node['_' + this.power_id];
                            // 为了在生成菜单时便于使用模板函数for进行遍历，将同级子节点作为数组存放在上级对象中
                            power._childs.push(this.power_code);
                        } else {
                            // 否则，将临时对象中的上下级对象进行引用赋值（使用power_code作为键名）
                            if (!tmp_power_node['_' + this.parent_id]) {
                                tmp_power_node['_' + this.parent_id] = { _childs: [] }
                            }
                            tmp_power_node['_' + this.parent_id][this.power_code] = tmp_power_node['_' + this.power_id];
                            // 为了在生成菜单时便于使用模板函数for进行遍历，将同级子节点作为数组存放在上级对象中
                            tmp_power_node['_' + this.parent_id]._childs.push(this.power_code);
                        }
                    });
                    uim.session.power = power;
                    uim.save('session');
                    toastr.success('登录成功')
                    initApp.playSound('media/sound', 'voice_on')
                    setTimeout(function () {
                        uim.view('index');
                    }, 1000);
                }, error: function (ret) {
                    toastr.warning('获取账号权限失败', ret.text)
                    return true;
                }
            })
        }
    </script>
</body>

</html>